package com.paic.mhis.hcpms.workingArea.web.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.paic.mhis.core.auth.biz.service.UserDetails;
import com.paic.mhis.hcpms.common.base.util.PropertyCopyUtil;
import com.paic.mhis.hcpms.warning.dto.PaginationQueryDTO;
import com.paic.mhis.hcpms.warning.util.WarnConstants;
import com.paic.mhis.hcpms.warning.web.vo.WarningGtasksVO;
import com.paic.mhis.hcpms.workingArea.biz.service.WarnWorkingAreaService;
import com.paic.pafa.appclient.annotation.BizServicesProxy;

/**
 * 预警 我的工作区
 * 
 * @author EX-chenyonghong001
 * 
 */
@Controller
@RequestMapping("/warnWorkingArea/")
public class WarnWorkingAreaController {

	@BizServicesProxy(beanName = "warnWorkingAreaService")
	private WarnWorkingAreaService warnWorkingAreaService;

	/**
	 * 查询预警 审批列表
	 * 
	 * @param
	 * @return
	 */
	@RequestMapping(value = "findWarningApproveList.do")
	@ResponseBody
	public Map<String, Object> findWarningApproveList(@ModelAttribute WarningGtasksVO taskVo, HttpServletRequest request) {
		Map<String, Object> result = new HashMap<String, Object>();
		try {
			UserDetails user = (UserDetails) request.getSession().getAttribute("user");
			PaginationQueryDTO paginationCon = new PaginationQueryDTO();
			Map<String, Object> condition = new HashMap<String, Object>();
			PropertyCopyUtil.propertyCopyForMap(condition, taskVo);
			List<String> statusList = new ArrayList<String>();
			statusList.add(WarnConstants.WARN_STATUS_8);
			condition.put("statusList", statusList);
			condition.put("assigner", user.getUsername());
			condition.put("role", WarnConstants.WARN_APPROVER);
			paginationCon.setParam(condition);
			result = warnWorkingAreaService.getGTasks(paginationCon);
			result.put(WarnConstants.STATE_KEY, WarnConstants.SUCCESS_STATE_VALUE);
			result.put(WarnConstants.MSG_KEY, WarnConstants.SELECT_SUCCESS);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return result;
	}

	/**
	 * 查询预警 审核列表
	 * 
	 * @param
	 * @return
	 */
	@RequestMapping(value = "findWarningAuditList.do")
	@ResponseBody
	public Map<String, Object> findWarningAuditList(@ModelAttribute WarningGtasksVO taskVo, HttpServletRequest request) {
		Map<String, Object> result = new HashMap<String, Object>();
		try {
			UserDetails user = (UserDetails) request.getSession().getAttribute("user");
			PaginationQueryDTO paginationCon = new PaginationQueryDTO();
			Map<String, Object> condition = new HashMap<String, Object>();
			PropertyCopyUtil.propertyCopyForMap(condition, taskVo);
			List<String> statusList = new ArrayList<String>();
			statusList.add(WarnConstants.WARN_STATUS_4);
			condition.put("statusList", statusList);
			condition.put("assigner", user.getUsername());
			condition.put("role", WarnConstants.WARN_AUDIT);
			paginationCon.setParam(condition);
			result = warnWorkingAreaService.getGTasks(paginationCon);
			result.put(WarnConstants.STATE_KEY, WarnConstants.SUCCESS_STATE_VALUE);
			result.put(WarnConstants.MSG_KEY, WarnConstants.SELECT_SUCCESS);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return result;
	}

	/**
	 * 查询预警 结论审核列表
	 * 
	 * @param
	 * @return
	 */
	@RequestMapping(value = "findWarningResultAuditList.do")
	@ResponseBody
	public Map<String, Object> findWarningResultAuditList(@ModelAttribute WarningGtasksVO taskVo,
			HttpServletRequest request) {
		Map<String, Object> result = new HashMap<String, Object>();
		try {
			UserDetails user = (UserDetails) request.getSession().getAttribute("user");
			PaginationQueryDTO paginationCon = new PaginationQueryDTO();
			Map<String, Object> condition = new HashMap<String, Object>();
			PropertyCopyUtil.propertyCopyForMap(condition, taskVo);
			List<String> statusList = new ArrayList<String>();
			statusList.add(WarnConstants.WARN_STATUS_7);
			statusList.add(WarnConstants.WARN_STATUS_4);
			condition.put("statusList", statusList);
			condition.put("assigner", user.getUsername());
			condition.put("role", WarnConstants.WARN_AUDIT);
			paginationCon.setParam(condition);
			result = warnWorkingAreaService.getGTasks(paginationCon);
			result.put(WarnConstants.STATE_KEY, WarnConstants.SUCCESS_STATE_VALUE);
			result.put(WarnConstants.MSG_KEY, WarnConstants.SELECT_SUCCESS);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return result;
	}

	/**
	 * 查询预警 反馈评估列表
	 * 
	 * @param
	 * @return
	 */
	@RequestMapping(value = "findWarningAssessList.do")
	@ResponseBody
	public Map<String, Object> findWarningAssessList(@ModelAttribute WarningGtasksVO taskVo, HttpServletRequest request) {
		Map<String, Object> result = new HashMap<String, Object>();
		try {
			UserDetails user = (UserDetails) request.getSession().getAttribute("user");
			PaginationQueryDTO paginationCon = new PaginationQueryDTO();
			Map<String, Object> condition = new HashMap<String, Object>();
			PropertyCopyUtil.propertyCopyForMap(condition, taskVo);
			List<String> statusList = new ArrayList<String>();
			statusList.add(WarnConstants.WARN_STATUS_6);
			statusList.add(WarnConstants.WARN_STATUS_3);
			// statusList.add(WarnConstants.WARN_STATUS_2);
			condition.put("statusList", statusList);
			condition.put("assigner", user.getUsername());
			condition.put("role", WarnConstants.WARN_AGENT);
			paginationCon.setParam(condition);
			paginationCon.setLimit(taskVo.getLimit());
			paginationCon.setStart(taskVo.getStart());
			result = warnWorkingAreaService.getGTasks(paginationCon);
			result.put(WarnConstants.STATE_KEY, WarnConstants.SUCCESS_STATE_VALUE);
			result.put(WarnConstants.MSG_KEY, WarnConstants.SELECT_SUCCESS);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return result;
	}

	/**
	 * 查询预警 反馈评估列表
	 * 
	 * @param
	 * @return
	 */
	@RequestMapping(value = "findWarningCount.do")
	@ResponseBody
	public Map<String, Object> findWarningCount(@RequestParam(value = "type") String type, HttpServletRequest request) {
		Map<String, Object> result = new HashMap<String, Object>();
		try {
			UserDetails user = (UserDetails) request.getSession().getAttribute("user");
			PaginationQueryDTO paginationCon = new PaginationQueryDTO();
			Map<String, Object> condition = new HashMap<String, Object>();
			condition.put("assigner", user.getUsername());
			condition.put("type", type);
			condition.put("role", WarnConstants.WARN_AGENT);
			result = warnWorkingAreaService.findWarningCount(condition);
			result.put(WarnConstants.STATE_KEY, WarnConstants.SUCCESS_STATE_VALUE);
			result.put(WarnConstants.MSG_KEY, WarnConstants.SELECT_SUCCESS);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return result;
	}

}
